var express = require('express')
var app = express()
var login = require('../user/login')
var list = require('../review/list')
var listrevise = require('../review/listrevise')
var bodyParser = require('body-parser')
// 配置允许跨域请求；
app.all('*', function (req, res, next) {
  res.header('Access-Control-Allow-Origin', '*')
  res.header('Access-Control-Allow-Headers', 'Content-Type,Content-Length, Authorization, Accept,X-Requested-With')
  res.header('Access-Control-Allow-Methods', 'PUT,POST,GET,DELETE,OPTIONS')
  res.header('X-Powered-By', ' 3.2.1')
  next()
})
var responseJSON = function (res, ret) {
     if(typeof ret === 'undefined') { 
          res.json({
          	code:'400',
          	msg: '操作失败'
        }); 
    } else { 
      res.json(ret); 
  }};
// 获取本机ip地址
function getIp () {
  var os = require('os'),
    iptable = {},
    ifaces = os.networkInterfaces()
  for (var dev in ifaces) {
    ifaces[dev].forEach(function (details, alias) {
      if ((details.family == 'IPv4') && (details.internal == false)) {
        // iptable[dev+(alias?':'+alias:'')]=details.address
        iptable['localIP'] = details.address
      }
    })
  }
  return iptable.localIP
}
// 获取当月的天数
function getDaysInOneMonth (year, month) {
  month = parseInt(month, 10)
  var d = new Date(year, month, 0)
  return d.getDate()
}
// post请求需要
app.use(bodyParser.urlencoded({ 'limit': '10000kb','extended':true}))
// 登录接口
app.post('/login',bodyParser.json(),login)
// 列表查询
app.get('/review',list)
//修改列表状态
app.post('/review/revise',bodyParser.json(),listrevise)
app.use(express.static(__dirname + '/images'))
var server = app.listen(3000, function () {
  var port = server.address().port
  console.log('应用实例，访问地址为 http://localhost:', port)
})
